import instance from '../http/index.js'
// 获取用户信息
export const getUserInfo = (id) => {
    return instance({
        url: '/user/getUserInfo',
        method: 'POST',
        data: {
            id
        }
    })
}
//绑定图片地址跟账号
export const bindAccount = (account, onlyId, image_url) => {
    return instance({
        url: '/user/bindAccount',
        method: 'POST',
        data: {
            account,
            image_url,
            onlyId
        }
    })
}
//修改密码
export const changePassword = (id, newPassword, oldPassword) => {
    return instance({
        url: '/user/changePassword',
        method: 'POST',
        data: {
            id,
            newPassword,
            oldPassword
        }
    })
}

//修改姓名
export const changeName = (id, name) => {
    return instance({
        url: '/user/changeName',
        method: 'POST',
        data: {
            id,
            name
        }
    })
}

//修改性别
export const changeSex = (id, sex) => {
    return instance({
        url: '/user/changeSex',
        method: 'POST',
        data: {
            id,
            sex
        }
    })
}

//修改邮箱
export const changeEmail = (id, email) => {
    return instance({
        url: '/user/changeEmail',
        method: 'POST',
        data: {
            id,
            email
        }
    })
}

//-------------------------------------------------------------用户管理
//添加管理员
export const createAdmin = (Data) => {
    const {
        account,
        password,
        name,
        sex,
        identity,
        department,
        email
    } = Data
    return instance({
        url: '/user/createAdmin',
        method: 'POST',
        data: {
            account,
            password,
            name,
            sex,
            identity,
            department,
            email
        }
    })
}

//获取管理员列表
export const getAdminList = (identity) => {
    return instance({
        url: '/user/getAdminList',
        method: 'POST',
        data: {
            identity
        }
    })
}

//编辑管理员账号信息
export const editAdmin = (Data) => {
    const {
        id,
        name,
        sex,
        email,
        department
    } = Data;
    return instance({
        url: '/user/editAdmin',
        method: 'POST',
        data: {
            id,
            name,
            sex,
            email,
            department
        }
    })
}

//对管理员取消赋权
export const changeIdentityToUser = (id) => {
    return instance({
        url: '/user/changeIdentityToUser',
        method: 'POST',
        data: {
            id
        }
    })
}
//对管理员进行赋权 参数id identity
export const changeIdentityToAdmi = (id, identity) => {
    return instance({
        url: '/user/changeIdentityToAdmin',
        method: 'POST',
        data: {
            id,
            identity
        }
    })
}
//通过账号对用户搜索 参数是account
export const searchUser = (account) => {
    return instance({
        url: '/user/searchUser',
        method: 'POST',
        data: {
            account
        }
    })
}
//通过部门对用户搜索 参数是department
export const searchUserByDepartment = (department) => {
    return instance({
        url: '/user/searchUserByDepartment',
        method: 'POST',
        data: {
            department
        }
    })
}

//冻结用户 把status改为1
export const banUser = (id) => {
    return instance({
        url: '/user/banUser',
        method: 'POST',
        data: {
            id
        }
    })
}
//解冻用户
export const unbanUser = (id) => {
    return instance({
        url: '/user/unbanUser',
        method: 'POST',
        data: {
            id
        }
    })
}
//获取冻结用户列表
export const getBanUserList = () => {
    return instance({
        url: '/user/getBanUserList',
        method: 'POST'
    })
}
//删除用户 id
export const deleteUser = (id,account) => {
    return instance({
        url: '/user/deleteUser',
        method: 'POST',
        data: {
            id,
            account
        }
    })
}
//获取对应身份的总人数
export const getAdminListLength = (identity) => {
    return instance({
        url: '/user/getAdminListLength',
        method: 'POST',
        data: {
            identity
        }
    })
}

//监听换页返回数据 页码 page identity
export const returnListData = (page, identity) => {
    return instance({
        url: '/user/returnListData',
        method: 'POST',
        data: {
            page,
            identity
        }
    })
}